﻿using EntityFrameworkSample.Adapters;
using EntityFrameworkSample.Adapters.Data;
using EntityFrameworkSample.Adapters.Mock;
using EntityFrameworkSample.Data;
using EntityFrameworkSample.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EntityFrameworkSample.Controllers
{
    public class HomeController : Controller
    {
        private IHomeAdapter adapter;

        public HomeController()
        {
            adapter = new HomeDataAdapter();
        }

        public HomeController(IHomeAdapter a)
        {
            adapter = a;
        }

        public ActionResult Index()
        {
            EnrollmentViewModel model = adapter.GetEnrollmentViewModel();

            return View(model);        
        }

        public ActionResult CreateStudent()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CreateStudent(StudentViewModel model)
        {
            adapter.CreateStudent(model);
            return RedirectToAction("Index");
        }

        public ActionResult UpdateStudent(int id)
        {
            StudentViewModel model = adapter.GetStudentViewModel(id);

            return View(model);
        }

        [HttpPost]
        public ActionResult UpdateStudent(StudentViewModel model)
        {
            adapter.UpdateStudent(model);
            return RedirectToAction("Index");
        }

        public ActionResult About()
        {

            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}